package ctrl

import (
	"cyiris/app/demo/biz"
	"cyiris/app/filter"
	"cyiris/core/http"
	log "cyiris/core/zaplog"
)

type DemoCtrl struct {
	http.Ctrl
	biz *biz.TestBiz
}

func NewDemoCtrl() *DemoCtrl {
	c := &DemoCtrl{
		Ctrl: http.NewBaseCtrl(),
		biz:  biz.NewTestBiz(),
	}

	c.AddFilter(&filter.TestFilter{})

	return c
}

func (ctrl *DemoCtrl) Action(ctx *http.Context) {
	log.Debugf("handle demo ctrl")

	name := ctx.FormValue("name")
	email := ctx.FormValue("email")

	if name == "" || email == "" {
		ctx.Error(-1, "params error")
		return
	}

	ctx.Success(ctrl.biz.Handle(name, email))
}
